-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-752: Add maxStalenessMS to ReadPreference class #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, array(array("tag" => "one")))); | ||
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, array())); | ||
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_SECONDARY, [['tag' => 'one']])); | ||
var_dump(new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY, [])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just array()
to []
refactoring here. Since this is the only ReadPreference constructor test, I added a new case for "maxStalenessMS" below; however, it's probably redundant in light of the ReadPreference::getMaxStalenessMS()
test.
@@ -46,21 +46,22 @@ PHONGO_API zend_class_entry *php_phongo_readpreference_ce; | |||
|
|||
zend_object_handlers php_phongo_handler_readpreference; | |||
|
|||
/* {{{ proto void ReadPreference::__construct(integer $mode[, array $tagSets = array()]) | |||
/* {{{ proto void ReadPreference::__construct(integer $mode[, array $tagSets = array()[, integer $maxStalenessMS]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would much rather see this being an options array, as it is possible that other options might be added in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll refactor this to expect an options array and check a "maxStalenessMS" value.
@@ -1,5 +1,5 @@ | |||
--TEST-- | |||
MongoDB\Driver\ReadPreference::getMode() | |||
MongoDB\Driver\ReadPreference::getTagSets() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit doesn't really belong here, perhaps in #399.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a stand-alone commit akin to any typo fix. The PR should make no difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to #408.
8e37c11
to
8bb7d70
Compare
case 2: | ||
if (tagSets) { | ||
bson_t *tags = bson_new(); | ||
if (tagSets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I removed the switch
statement and am processing tagSets
first, I added a test that tag set exceptions are thrown before maxStalenessMS.
@@ -0,0 +1,54 @@ | |||
--TEST-- | |||
MongoDB\Driver\Manager::__construct(): read preference options of the wrong type are ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to change this behavior in the future, but this is how processing of Manager options operates today. We can revise this test if we decide to change this in the future.
I'll note that mongoc-uri.c
is also quite lax about type errors. For instance, options that are expected to be integers are run through strtol()
with no error handling.
@@ -1,13 +0,0 @@ | |||
--TEST-- | |||
MongoDB\Driver\Manager: maxStalenessMS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was essentially renamed to manager-ctor-read_preference-002.phpt
, where I added an additional test case and assert the state of Manager::getReadPreference()
.
@@ -1,33 +0,0 @@ | |||
--TEST-- | |||
MongoDB\Driver\Manager: maxStalenessMS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was renamed to manager-ctor-read_preference-error-002.phpt
, where I added an additional error case for an out-of-range value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, except for the inclusion of maxStalenessMS in debug output when it's not set, or using the default.
--EXPECTF-- | ||
object(MongoDB\Driver\ReadPreference)#%d (%d) { | ||
["mode"]=> | ||
int(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to fail/create conflicts after the PHPC-498 changes (ReadPreference, ReadConcern, and WriteConcern value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that because you're changing it to display the string name? If so, you can easily update this when PHPC-489 is implemented.
I have absolutely no reservations whatever about going back and modifying tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it turns into a string. I'll do the PHPC-489 tomorrow (Monday), should be ready for you to review when you wake up.
@@ -982,6 +982,8 @@ void php_phongo_read_preference_to_zval(zval *retval, const mongoc_read_prefs_t | |||
} else { | |||
ADD_ASSOC_NULL_EX(retval, "tags"); | |||
} | |||
|
|||
ADD_ASSOC_LONG_EX(retval, "maxStalenessMS", mongoc_read_prefs_get_max_staleness_ms(read_prefs)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be added if maxstaleness is the default (0), just like we're no longer to do that for "journal", "w", etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
array(0) { | ||
} | ||
["maxStalenessMS"]=> | ||
int(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be excluded here (As mentioned in an earlier comments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
2b62d20
to
a9e9776
Compare
@@ -963,7 +963,7 @@ void php_phongo_read_preference_to_zval(zval *retval, const mongoc_read_prefs_t | |||
{ | |||
const bson_t *tags = mongoc_read_prefs_get_tags(read_prefs); | |||
|
|||
array_init_size(retval, 2); | |||
array_init_size(retval, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess using 3 when there are only 2 items is fine, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just controls the initial HashTable size, so it should be fine. The buckets are still empty until we fill them.
This adds an options array to the ReadPreference constructor, which accepts a maxStalenessMS option. The option is also exposed via a getter method and in debug output.
This also adds various tests for parsing of read preference Manager options.
https://jira.mongodb.org/browse/PHPC-752
I was premature in signing off on #380, as it was lacking support for maxStalenessMS on the ReadPreference object. This adds a new constructor argument, getter method, and adds "maxStalenessMS" to the ReadPreference debug output.